#include <QThreadPool>
#include "oxford-3000-list.h"
#include "oxford-3000-updater.h"
#include "oxford-word-provider.h"
#include "oxford-word-updater.h"

using namespace Oxford;

Oxford3000List::Oxford3000List()
{
    databaseManager = new Core::DatabaseManager("Oxford");
}

Oxford3000List::~Oxford3000List()
{
    delete databaseManager;
}

QString Oxford3000List::name() const
{
    return "The Oxford 3000";
}

QString Oxford3000List::description() const
{
    return "The keywords of the Oxford 3000 have been carefully selected by a group of language experts and experienced teachers as the words which should receive priority in vocabulary study because of their importance and usefulness.";
}

QString Oxford3000List::getRandomWord()
{
    return databaseManager->getRandomListItem("Oxford3000");
}

QStringList Oxford3000List::getList()
{
    return databaseManager->getList("Oxford3000");
}

void Oxford3000List::update()
{
    List3000Updater *updater = new List3000Updater();
    updater->setAutoDelete(true);
    QObject::connect(updater, SIGNAL(updateFinished()), this,  SLOT(updated()));
    QThreadPool::globalInstance()->start(updater);
}

void Oxford::Oxford3000List::updated()
{
    WordUpdater *updater = new WordUpdater();
    updater->setAutoDelete(true);
    updater->setDeepMode(false);
    updater->setWordsList(getList());

    QThreadPool::globalInstance()->start(updater);
}
